import request from "@/assets/request";
import axios from "@/assets/request/request";
import { Video, VideoRankType, PageByUserId } from "@/types/video";
import { isNull } from "@/utils/common.js";
import { PageResp } from "@/types/page";

export default {
  getVideoById: (videoId: string) => {
    return axios({
      url: `/video/${videoId}`,
      method: "get",
    });
  },
  save: (data: Video) => {
    return axios({
      url: "/video",
      method: "post",
      data: data,
    });
  },
  getByUserId: (params: PageByUserId) => {
    return request.get<PageResp<Video>>(`/video/getByUserId`, params);
  },
  getRecommendVideo: (params: { count: number; channelId?: number }) => {
    return axios({
      url: `/video/getRecommend`,
      method: "get",
      params: params,
    });
  },
  getRank: (type: VideoRankType, channelId: number | null, count: number) => {
    let data = {
      url: `/video/getRank/${type}/${count}`,
      method: "get",
      params: {},
    };

    if (channelId !== null && channelId === channelId) {
      data.params = { channelId: channelId };
    }
    return axios(data);
  },
  getDynamic: (params: { pageIndex: number; pageSize: number }) => {
    return axios({
      url: `/video/getDynamic/${params.pageIndex}/${params.pageSize}`,
      method: "get",
    });
  },
  // 获取自己发布的视频信息
  getIdTitle: () => {
    return request.get<Video[]>("/video/getIdTitle");
  },
  remove: (videoId: Video["id"]) => {
    return request.delete<string>(`/video/${videoId}`);
  },
  update: (videoInfo: Video) => {
    return request.put<string>(`/video`, videoInfo);
  }
};
